<template>
  <el-row>
    <!--     历史借款订单-->
    <el-table
      v-loading="loading"
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      :data="tableData"
      border
      :stripe="true"
      style="width: 100%;"
    >
      <el-table-column
        fixed="left"
        prop="creditOrderNo"
        :label="tableText['creditOrderNo']"
        min-width="180"
      >
        <template slot-scope="scope">
          <el-button type="text" @click="auth(scope.row)">
            {{ scope.row.creditOrderNo }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        fixed="left"
        prop="orderNo"
        :label="tableText['orderNo']"
        min-width="180"
      >
        <template slot-scope="scope">
          <el-button type="text" @click="orderDetail(scope.row)">
            {{ scope.row.orderNo }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTimeStr"
        :label="tableText['createTime']"
        min-width="150"
      />
      <el-table-column
        prop="userAccount"
        :label="tableText['account']"
        min-width="150"
      />
      <el-table-column
        prop="userName"
        :label="tableText['name']"
        min-width="100"
      />
      <el-table-column
        prop="userGrade"
        :label="tableText['userGrade']"
        min-width="100"
      />
      <el-table-column
        prop="orderType"
        :label="tableText['productType']"
        min-width="250"
      >
        <template slot-scope="scope">
          {{ scope.row.orderType !== null ? $t('authModule.orderDetail.orderType')[scope.row.orderType] : '' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="applyMoney"
        :label="tableText['applyMoney']"
        min-width="150"
      />
      <el-table-column
        prop="loanDays"
        :label="tableText['limit']"
        min-width="150"
      />
      <el-table-column
        prop="payMoney"
        :label="tableText['loanRepay']"
        min-width="150"
      />
      <el-table-column
        prop="payDateStr"
        :label="tableText['loanRepayTime']"
        min-width="120"
      />
      <el-table-column
        prop="currentRepay"
        :label="tableText['currentRealRepay']"
        min-width="170"
      />
      <el-table-column
        prop="principal"
        :label="tableText['principal']"
        min-width="100"
      />
      <el-table-column
        prop="interestMoney"
        :label="tableText['lendRateMoney']"
        min-width="100"
      />
      <el-table-column
        prop="otherCost"
        :label="tableText['otherFee']"
        min-width="180"
      />
      <el-table-column
        prop="overDueFine"
        :label="tableText['overDueRateMoney']"
        min-width="150"
      />
      <el-table-column
        prop="dueDays"
        :label="tableText['dueDays']"
        min-width="100"
      />
      <el-table-column
        prop="realRepayMoney"
        :label="tableText['realRepayMoney']"
        min-width="180"
      />
      <el-table-column
        prop="realRepaymentDateStr"
        :label="tableText['realRepaymentDate']"
        min-width="150"
      />
      <el-table-column
        fixed="right"
        prop="orderStatus"
        :label="tableText['status']"
        min-width="100"
      >
        <template slot-scope="scope">
          {{ setState(scope.row.orderStatus) }}
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="pageSize"
        :total="totalNumber"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </el-row>
</template>

<script>
import { orderUnionQuery } from '@/api/user'
import { ObjToQueryString } from '@/utils/method'
export default {
  name: 'LoanOrder',
  data() {
    return {
      loading: true,
      para: {},
      tableText: {},
      tableData: [],
      totalNumber: 0,
      currentPage: 1,
      pageSize: 10
    }
  },
  mounted() {
    this.para = this.$route.query
    this.tableText = this.$t('authModule.historyOrder')
    this.getData()
  },
  methods: {
    getData() {
      this.loading = true
      const data = {
        userId: this.para.userId,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }
      orderUnionQuery(data)
        .then(res => {
          this.loading = false
          if (res.success) {
            this.tableData = res.data
            this.totalNumber = res.page ? res.page['totalNumber'] : 0
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error(err.message)
        })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getData()
    },
    auth(item) {
      const paramData = {
        from: 'auditedList',
        status: item['status'],
        userId: item['userId'],
        orderId: item['id'],
        orderNo: item['creditOrderNo']
      }
      const para = ObjToQueryString(paramData)
      window.open(`${window.location.origin + window.location.pathname}#/usr/auth?${para}`, '_blank')
    },
    orderDetail(item) {
      const paramData = {
        orderId: item['id'],
        userId: item['userId']
      }
      const para = ObjToQueryString(paramData)
      window.open(`${window.location.origin + window.location.pathname}#/order/detail?${para}`, '_blank')
    },
    setState(data) {
      if (data !== null) {
        const name = this.$t('orderList.allList.orderStatusEnum').filter(v => {
          return v['value'] === data
        })
        return (name && name[0] && name[0]['desc']) ? name[0]['desc'] : ''
      }
    }
  }
}
</script>

<style scoped>

</style>
